<template>
	<view class="list">
		<view class="fixbg" :style="{'background-image':'url('+playlist.coverImgUrl+')'}"></view>
		<musichead title='歌单' :icon='true' color='white'></musichead>
		<view class="container" v-show="!isLoading">
			<scroll-view scroll-y="true">
				<view class="list-head">
					<!-- 左侧图片布局 -->
					<view class="list-head-img">
						<image :src="playlist.coverImgUrl" mode=""></image>
						<text class="iconfont icon-yousanjiao">{{playlist.playCount | formatCount}}</text>
					</view>
					<!-- 右侧文字布局 -->
					<view class="list-head-text">
						<view>{{playlist.name}}</view>
						<view>
							<image src="@/static/wangyiyunlogo.png" mode=""></image>网易云音乐
						</view>
						<view>
							{{playlist.description}}
						</view>
					</view>

				</view>
				<!-- 只适配微信 条件编译，做差异化处理 -->
				<!-- #ifdef MP-WEIXIN -->
				<!-- 分享给朋友框 -->
				<button class="list-share" open-type="share">
					<text class="iconfont icon-fenxiang"></text>分享给微信好友
				</button>
				<!-- #endif -->
				<!-- 下面的歌曲列表渲染 -->
				<view class="list-music">
					<view class="list-music-head">
						<text class="iconfont icon-bofang1"></text>
						<text>播放全部</text>
						<text>(共{{playlist.trackCount}}首)</text>
					</view>
					<view class="list-music-item" v-for="(item,index) in playlist.tracks" :key='item.id' @tap="handleToDetail(item.id)">
						<view class="list-music-top">{{index+1}}</view>
						<view class="list-music-song">
							<view>{{item.name}}</view>
							<view class="list-music-img">
								<image v-if="privileges[index].flag>60 && privileges[index].flag<70" src="@/static/dujia.png" mode=""></image>
								<image v-if="privileges[index].maxbr==999000" src="@/static/sq.png" mode=""></image>
								{{item.ar[0].name}} - {{item.name}}
							</view>
						</view>
						<!-- 播放按钮 -->
						<text class="iconfont icon-bofang"></text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import musichead from '@/components/musichead/musichead.vue'
	import {list} from '@/common/api.js'
	export default {
		data() {
			return {
				playlist:{
					coverImgUrl:''
				},
				//存储是否是独家和无损
				privileges:[],
				//确保已经加载完毕
				isLoading:true
			}
		},
		components: {
			musichead
		},
		onLoad(options) {
			
			uni.showLoading({
				title:'加载中...'
			})
			
			list(options.id).then(res => {
				if(res[1].data.code=='200') {
					console.log(res[1].data);
					let playList=res[1].data.playlist
					let Privileges=res[1].data.privileges
					this.playlist=playList
					this.privileges=Privileges
					this.$store.commit('INIT_TOPLISTIDS',res[1].data.playlist.trackIds)
					this.isLoading=false
					uni.hideLoading()
				}
				
			})
			
		},
		methods: {
		handleToDetail(id) {
			uni.navigateTo({
				url:'/pages/detail/detail?songId=' + id
			})
		}
		}
	}
</script>

<style scoped>
	.list-head {
		display: flex;
		margin: 30rpx;
	}

	.list-head-img {
		width: 264rpx;
		height: 264rpx;
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		margin-right: 42rpx;
	}

	.list-head-img image {
		width: 100%;
		height: 100%;
	}

	.list-head-img text {
		position: absolute;
		top: 8rpx;
		right: 8rpx;
		color: #FFFFFF;
		font-size: 26rpx;
	}

	.list-head-text {
		flex: 1;
		color: #f0f2f7;
	}

	.list-head-text view:nth-child(1) {
		color: #FFFFFF;
		font-size: 34rpx;
	}

	.list-head-text view:nth-child(2) {
		display: flex;
		margin: 20rpx 0;
		font-size: 24rpx;
		/* 上下对齐 */
		align-items: center;
	}

	.list-head-text view:nth-child(2) image {
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;
		overflow: hidden;
		margin-right: 10rpx;
	}

	.list-head-text view:nth-child(3) {
		line-height: 34rpx;
		font-size: 22rpx;
	}

	.list-share {
		width: 330rpx;
		height: 74rpx;
		margin: 0 auto;
		background: rgba(0, 0, 0, 0.4);
		border-radius: 37rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 74rpx;
		font-size: 28rpx;
	}

	.list-share text {
		margin-right: 16rpx;
	}
	.list-music {
		background: #FFFFFF;
		border-radius: 50rpx;
		margin-top: 40rpx;
		overflow: hidden;
	}
	.list-music-head {
		height: 50rpx;
		margin: 30rpx 0 70rpx 22rpx;
	}
	.list-music-head text:nth-child(1){
		height: 50rpx;
		font-size: 50rpx;
	}
	.list-music-head text:nth-child(2){
		font-size: 30rpx;
		margin: 0 10rpx 0 26rpx;
	}
	.list-music-head text:nth-child(3){
		font-size: 26rpx;
		color: #b2b2b2;
	}
	.list-music-top {
		width: 58rpx;
		font-size: 30rpx;
		line-height: 30rpx;
	}
	
	.list-music-item {
		display: flex;
		margin: 0 32rpx 66rpx 46rpx;
		align-items: center;
		color: #959595;
	}
	.list-music-song {
		flex: 1;
	}
	.list-music-song view:nth-child(1) {
		font-size: 28rpx;
		color: black;
		width: 70vw;
		/* 只在一行显示，多出省略 */
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.list-music-img {
		font-size: 20rpx;
		align-items: center;
		width: 70vw;
		/* 只在一行显示，多出省略 */
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.list-music-img image {
		width: 32rpx;
		height: 20rpx;
		margin-right: 10rpx;
	}
	.list-music-item text {
		font-size: 50rpx;
		color: #c7c7c7;
	}
</style>
